EntityLiquidBlock = class(EntityBlock)
EntityLiquidBlock.WaterTicks = 16
EntityLiquidBlock.LavaTicks = 40

function EntityLiquidBlock:init(liquidBlock,x,y,z)
    EntityBlock.init(self,liquidBlock,x,y,z)
    self.ticks = 0
end

function EntityLiquidBlock:update()
    if self.blockType.id == Block.water.id then
        if self.ticks <= EntityLiquidBlock.WaterTicks then
            self.ticks = self.ticks + 1
        else
            self:updateLiquid()
        end
    else
        if self.ticks <= EntityLiquidBlock.LavaTicks then
            self.ticks = self.ticks + 1
        else
            self:updateLiquid()
        end
    end
end

function EntityLiquidBlock:updateLiquid()
    local x,y,z = self.x,self.y,self.z
    local id = self.blockType.id
    if world:isSolidBlock(x,y - 1,z) then
        self:cheakLiquid(x - 1,y,z,id)
        self:cheakLiquid(x + 1,y,z,id)
        self:cheakLiquid(x,y,z - 1,id)
        self:cheakLiquid(x,y,z + 1,id)
    end
    self:cheakLiquid(x,y - 1,z,id)
    self.removed = true
end

function EntityLiquidBlock:cheakLiquid(x,y,z,id)
    if world:isSolidBlock(x,y,z) == false then
        if id == Block.water.id then
            if world:getBlock(x,y,z) == Block.lava.id then
                world:setBlock(x,y,z,Block.cobbleStone.id)
            else
                world:setBlock(x,y,z,id)
            end
        else
            if world:getBlock(x,y,z) == Block.water.id then
                world:setBlock(x,y,z,Block.cobbleStone.id)
            else
                world:setBlock(x,y,z,id)
            end
        end
    end
end
